package com.ruoyi.web.controller.document;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: fulin
 * @Date: 2023/07/16/10:07
 * @Description:
 */

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.config.ArticleSocketServer;
import com.ruoyi.system.domain.Article;
import com.ruoyi.system.mapper.ArticleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 在线用户监控
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/document/work")
public class WorkController {

    @Autowired
    private ArticleMapper articleMapper;
    @Autowired
    private ArticleSocketServer articleSocketServer;

    @PreAuthorize("@ss.hasPermi('work:view:list')")
    @GetMapping("/list")
    public AjaxResult list()
    {
        return AjaxResult.success();
    }

    @PostMapping("/save/{id}")
    public AjaxResult save(@PathVariable("id")String id, @RequestBody String data){
        Article article = articleMapper.save(data, id);
        // 更新缓存用户权限
        LoginUser loginUser =  SecurityUtils.getLoginUser();
        new Thread(()->articleSocketServer.sendMessage(article,String.valueOf(loginUser.getUserId()))).start();
        return AjaxResult.success();
    }
}
